package com.lightkits.wms.controller;

import com.lightkits.framework.common.exception.LightKitsBizException;
import com.lightkits.framework.common.model.IResult;
import com.lightkits.wms.domain.stocktransfer.*;
import com.lightkits.wms.domain.stocktransfer.service.OrgSubStockTransDomain;
import com.lightkits.wms.dto.stocktransfer.*;
import io.choerodon.swagger.annotation.Permission;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;


/**
 * SubStockTransferService
 *
 * @author jing.wei@hand-china.com
 * @date 2019/4/17 15:23
 */
/*@LightKitsContract(serviceName = "SubStockTransferService", serviceNamespace = "center.soa.os-wms.com")*/
/*@SuppressWarnings("all")*/
@RestController
@RequestMapping("/SubStockTransferService")
public class SubStockTransferController {

    @PostMapping(value = "/subStockTransfer")
    @Permission(permissionPublic = true)
    @ApiOperation(value = "/subStockTransfer")
    @ResponseBody
    public SubStockTransferResponseType subStockTransfer(@RequestBody(required = false) SubStockTransferRequestType request) {
        return subStockTransferExecutor.service(request);
    }

    @Autowired
    private SubStockTransferExecutor subStockTransferExecutor;

    @PostMapping(value = "/miscellAdjust")
    @Permission(permissionPublic = true)
    @ApiOperation(value = "/miscellAdjust")
    @ResponseBody
    public MiscellAdjustResponseType miscellAdjust(@RequestBody(required = false) MiscellAdjustRequestType request) {
        return miscellAdjustExecutor.service(request);
    }

    @Autowired
    private MiscellAdjustExecutor miscellAdjustExecutor;

    @Autowired
    private OrgSubStockTransDomain orgSubStockTransDomain;

    @PostMapping(value = "/orgSubTrans")
    @Permission(permissionPublic = true)
    @ApiOperation(value = "/orgSubTrans")
    @ResponseBody
    public OrgSubStockTransResponseType orgSubTrans(@RequestBody(required = false)
                                                            OrgSubStockTransRequestType request) {
        OrgSubStockTransResponseType response = new OrgSubStockTransResponseType();
        response.setSuccessful(true);
        try {
            IResult result = orgSubStockTransDomain.orgSubStockTrans(request.getViewDto());
            if (!result.isSuccessful()) {
                return result.fill(response);
            }
        } catch (LightKitsBizException e) {
            e.fill(response);
        } catch (Exception e) {
            e.printStackTrace();
            response.setSuccessful(false);
            response.setMessage("Organization Stock Transfer Error");
        }
        return response;
    }
}
